<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
	File: 	http://iewiki.net/UploadDialog.htm
	Version	2007-06-23 18:00 
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>UploadDialog</title>
		<script type="text/javascript">
function init()
{
	var bImg = window.location.search.length > 1;
	if (bImg == false)
		setStylesheet("*.imgctl { visibility: hidden }");
		
	var fid = document.getElementById("upldlg");
	fid.setAttribute("action",window.location.hash.substr(1));

	var pw = window.parent;
	var pd = pw.document;
	var dud = pd.getElementById("displayUploads");
	var upldfndiv = document.getElementById("uploadedFilename");
	var upldftype = document.getElementById("uploadedFiletype");
	if (upldfndiv && upldftype)
	{
		var ftype = upldftype.firstChild.nodeValue;
		var fname = upldfndiv.firstChild.nodeValue;
		var fnsp = fname.lastIndexOf(".");
		var fnxt = fnsp > 0 ? fname.substr(0,fnsp) : fname;
		var	text = ftype == "image/jpeg" ? "<<image '" + fname + "' < 50%>>" : "[[" + fname + "|" + fname + "]]";
		var action = 'InsertTiddlerText("'.concat( fnxt, '","', text, '","',window.location.search.substr(1), '")');
		pw.setTimeout(action,1);

		if (dud)
		{
			// and/or just list the tiddler:
			pw.createTiddlyLink(dud,fnxt,true);
			dud.appendChild(pd.createElement("br"));
		}
	}
	var dur = pd.getElementById("displayUploadResult");
	if (dur)
	{
		while(dur.hasChildNodes())
			dur.removeChild(dur.firstChild);
			
		var mur = document.getElementById("displayUploadResult");
		moveElements(mur,dur,pd);
	}
}
function setStylesheet(s,id)
{
	if(!id)
		id = "customStyleSheet";
	var n = document.getElementById(id);
	if(document.createStyleSheet) // Test for IE's non-standard createStyleSheet method
		{
		if(n)
			n.parentNode.removeChild(n);
		// This failed without the &nbsp;
		document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd","&nbsp;<style id='" + id + "'>" + s + "</style>");
		}
	else
		{
		if(n)
			n.replaceChild(document.createTextNode(s),n.firstChild);
		else
			{
			var n = document.createElement("style");
			n.type = "text/css";
			n.id = id;
			n.appendChild(document.createTextNode(s));
			document.getElementsByTagName("head")[0].appendChild(n);
			}
		}
}

function moveElements(se,de,dd)
{
	while (se.hasChildNodes())
	{
		var sc = se.firstChild;
		var c, i;
		if (se.firstChild.nodeType == 1)
		{
			c = dd.createElement(sc.tagName);
			for (i = 0; i < sc.attributes.length; i++)
			{
				var sca = sc.attributes.item(i);
				c.setAttribute(sc.attributes.item(i).nodeName,sc.attributes.item(i).nodeValue);
			}
			if (sc.hasChildNodes())
				moveElements(sc,c,dd);
			c.nodeValue = sc.nodeValue;
		}
		else
			c = dd.createTextNode(sc.nodeValue);

		de.appendChild(c);
		se.removeChild(sc);
	}
}

function valid() 
{
	var srcfn = document.upldlg.MyFile.value;
	if (srcfn == "") {
		alert("Please select the file to upload");
		return false;
	}
	else if (document.upldlg.filename.value == "") {
		fnp = srcfn.split('\\');
		if (fnp.length == 1)
			fnp = srcfn.split('/');
		document.upldlg.filename.value = fnp[fnp.length - 1];
	}
	return true;
}

function fileSelected()
{
	var fid = document.getElementById("filename");
	var sel = document.getElementById("existing");
	var v = sel.value;
	fid.value = v;
}

		</script>
	</head>
	<body onload="init();" style="font-family: arial,helvetica; font-size: .75em; background-color:Transparent;">
	<div id="displayUploadResult" visible="false">ULR</div>
	<form id="upldlg" name="upldlg" method="post" enctype="Multipart/Form-Data" onsubmit="return valid()">
		<table border=0>
		<td colspan=3>
		Select file to upload<br />
		<input name="MyFile" type="File" id="MyFile" size="70" onchange="valid()"/><br />
		</td>
		<tr>
		<td>
		Name the uploaded file<br />
		<input name="filename" type="text" id="filename" />
		</td>
		<td ><span class="imgctl">Align<br /><select name="align"><option>center</option><option>left</option><option>right</option></select></span></td>
		<td ><span class="imgctl">Width<br /><select name="width"><option>100%</option><option>67%</option><option>50%</option><option>33%</option></select></span><br /></td>
		</tr>
		</table>
		<input name="SubmitNewFile" type="Submit" id="Submit1" value="Upload file" />
		<!--&nbsp; Existing files:<select name="existing" id="SubmitNewFile" onchange="fileSelected()"><option></option>{1}</select>
		<input name="SubmitNewVersion" type="Submit" id="SubmitNewVersion" value="Replace existing file" /> -->
		<input name="method" type="hidden" id="method" value="uploadFile" />
	</form>
	<div id="uploadedFilename" style="display: none">UFL</div>
	<div id="uploadedFiletype" style="display: none">UFT</div>
	</body>
</html>
